Open In Colab

Introduction

Not long ago, making nice, interactive maps took lots of code or very expensive GIS software. There are several Python packages for making nice maps, and below is an example of folium (https://python-visualization.github.io/folium/), my favorite Python mapping package. This article will demonstrate:

Import Required Packages

Google Colab does include folium, but the version it uses does not support a couple handy feattures (setting popup size). Thus, we will install the latest compatable version. The package gpxpy is the easiest way to parse gpx files (one of the most common gps data formats), however, any xml parsing toolkit including python's built in parser can be used.

Download GPX Tracks for Strava Activities

The .gpx files are zipped on my Github page. The following code grabs them.

Loading Tabular Data

In Strava's bulk data download for a user's account is a .csv showing different attributes for each activity. Unfortunately, there was no way to join the tabular and spatial information without some unpleasant preprocessing. The .gpx files were named by their non-unique activity name as shown on Strava, so I mimicked windows' file nameing scheme in Excel and added the duplication number for each file into a new feature in the tabular data (num field). Thus, as long as you know the order of the downloading, you can join the two datasets. For example:
Morning_Run.gpx, Morning_Run (1).gpx, Morning_Run (2).gpx...

We then need to clean up the activity names and add the 'num' column to create a filename feature:

Parsing the GPX Files

These files contain millions of gps points, so the following parsing loop will process the gpx points for three maps is a single loop

strava_map1, built in this cell, is a simple feature location map where different activity types are symbolized by color. Additionally, I created a popup box with some important information and a png chart for the elevation profile for each activity. The other maps will be initialized in later cells using data from this parsing loop.

The loop:

Static Heatmap

Timeseries Heatmap

The default folium time slider class is designed for datasets with multiple occurances at each time step. My activities are mutually exclusive, so I needed to do some extra work to make it meaningful. I addressed this by adding history to the timeseries. At each time step, the map shows not just what happened that day, but also previous days. In order to see trends over time, I deleted 3% of the points that are oldest, so the older activities decay as time moves on. Due to the large number of points and Colab contraints, I resampled these points by 400 (selected every 400th point), however you can run this on a personal computer with finer resolution.